/*----------------------------------------------------------------------------*/
/* Copyright (c) 2012 Worthington Kilbourne Robot Club. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package us.oh.k12.wkw.robot;

import java.util.Date;

/*import us.oh.k12.wkw.robot.command.ClimbingTiltPlungerDownCmd;
import us.oh.k12.wkw.robot.command.ClimbingTiltPlungerUpCmd;
import us.oh.k12.wkw.robot.command.DoNothingCmd;
import us.oh.k12.wkw.robot.command.LauncherAngleGoDownCmd;
import us.oh.k12.wkw.robot.command.LauncherAngleGoUpCmd;
import us.oh.k12.wkw.robot.command.LauncherAngleIncreaseSpeedCmd;
import us.oh.k12.wkw.robot.command.LauncherAngleStopCmd;
import us.oh.k12.wkw.robot.command.LauncherCompressorTurnOffCmd;
import us.oh.k12.wkw.robot.command.LauncherCompressorTurnOnCmd;
import us.oh.k12.wkw.robot.command.LauncherFireCmd;
import us.oh.k12.wkw.robot.command.LauncherMotorStartCmd;
import us.oh.k12.wkw.robot.command.LauncherMotorStopCmd;
import us.oh.k12.wkw.robot.command.LauncherPlungerFireCmd;
import us.oh.k12.wkw.robot.command.LauncherPlungerRetractCmd;
import us.oh.k12.wkw.robot.command.LauncherSpeedDecreaseCmd;
import us.oh.k12.wkw.robot.command.LauncherSpeedIncreaseCmd;
* */
import us.oh.k12.wkw.robot.util.SimpleDateFormat;
import us.oh.k12.wkw.robot.util.WkwFrcLogger;
import us.oh.k12.wkw.robot.util.WkwPrefs;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.buttons.InternalButton;
import edu.wpi.first.wpilibj.buttons.JoystickButton;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;

/**
 * Represents an operator interface.<br>
 * <br>
 * The joystick buttons:<br
 * 1 = trigger<br>
 * 2 = top rear<br>
 * 3 = top center<br>
 * 4 = top left<br>
 * 5 = top right<br>
 * 6, 7 = base left side<br>
 * 8, 9 - base back side<br>
 * 10, 11 - base right side.
 * 
 */
public class OperatorInterface {

	private Joystick leftJoystick;
	private Joystick rightJoystick;
	private Joystick launcherJoystick;

	private InternalButton testButton;
	private InternalButton test2Button;

	public OperatorInterface() {

		super();

		try {

			this.setupLeftJoystick();

			this.setupRightJoystick();

			this.setupLauncherJoystick();

			this.setupInternalButtons();

		} catch (Exception anEx) {
			this.error("OperatorInterface()", anEx);
		}
	}

	private void setupInternalButtons() {

		try {

			this.testButton = new InternalButton();
			SmartDashboard.putData("Test Button", this.testButton);
			//this.testButton.whenPressed(new DoNothingCmd());

			this.test2Button = new InternalButton();
			SmartDashboard.putData("Fire Button", this.test2Button);
			//this.test2Button.whenPressed(new LauncherFireCmd());

		} catch (Exception anEx) {
			this.error("setupInternalButtons()", anEx);
		}
	}

	

	public Joystick getLeftJoystick() {
		return this.leftJoystick;
	}

	public Joystick getRightJoystick() {
		return this.rightJoystick;
	}

	public Joystick getLauncherJoystick() {
		return this.launcherJoystick;
	}

	/*
	 * 
	 * 
	 * helper methods.
	 */

	protected void debug(final String pMethod, final String pMessage) {
		WkwFrcLogger.debug(this.getClassName(), pMethod, pMessage);
	}

	protected void info(final String pMethod, final String pMessage) {
		WkwFrcLogger.info(this.getClassName(), pMethod, pMessage);
	}

	private String formatException(final Exception pEx) {
		return (null == pEx ? "." : pEx.getClass().getName() + ", message=" + pEx.getMessage()
				+ ".");
	}

	protected void error(final String pMethod, final Exception pEx) {
		this.error(pMethod, this.formatException(pEx), pEx);
	}

	protected void error(final String pMethod, final String pMessage, final Exception pEx) {
		WkwFrcLogger.error(this.getClassName(), pMethod, pMessage, pEx);
		if (null != pEx) {
			pEx.printStackTrace();
		}
	}

	protected String getDateTimeFormatted() {
		final SimpleDateFormat aformat = new SimpleDateFormat();
		return aformat.format(new Date());
	}

	protected String getClassName() {
		String aClassName = this.getClass().getName();
		return aClassName.substring(aClassName.lastIndexOf('.') + 1);
	}

    private void setupLeftJoystick() {
        
       this.leftJoystick = new Joystick(WkwPrefs.getJoystickLeftPort());
    }

    private void setupRightJoystick() {
        
        this.rightJoystick = new Joystick(WkwPrefs.getJoystickRightPort());
    }

    private void setupLauncherJoystick() {
        
        this.launcherJoystick = new Joystick(WkwPrefs.getGamepadPort());
    }

}
